﻿package mortal.game.view.copy.defenseCopy.view
{
    import Message.DB.Tables.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import fl.data.*;
    import mortal.component.gComplexList.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.defenseCopy.*;
    import mortal.mvc.core.*;

    public class DefenseCopyUnfold extends GComplexListUnfoldBase
    {
        private var _list:GTileList;
        private var _bg:ScaleBitmap;
        private var _color:int;
        private var _hh:Number;

        public function DefenseCopyUnfold()
        {
            return;
        }// end function

        private function filterFun(param1:TDefenseCopyShopSell, param2:int, param3:Array) : Boolean
        {
            var _loc_4:* = new ItemData(param1.itemCode);
            return _loc_4.itemInfo.color == this._color;
        }// end function

        private function sortFun(param1:TDefenseCopyShopSell, param2:TDefenseCopyShopSell) : int
        {
            var _loc_3:* = new ItemData(param1.itemCode);
            var _loc_4:* = new ItemData(param2.itemCode);
            if (_loc_3.itemInfo.color < _loc_4.itemInfo.color)
            {
                return -1;
            }
            if (_loc_3.itemInfo.color > _loc_4.itemInfo.color)
            {
                return 1;
            }
            if (_loc_3.itemCode < _loc_4.itemCode)
            {
                return -1;
            }
            if (_loc_3.itemCode > _loc_4.itemCode)
            {
                return 1;
            }
            return 0;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_3:Array = null;
            var _loc_4:Array = null;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:TDefenseCopyShopSell = null;
            var _loc_2:* = Cache.instance.copy.defenseCopy.curTab;
            this._color = param1 as int;
            if (DefenseCopyUtil.isEquipTab)
            {
                _loc_3 = DefenseCopyShopConfig.instance.allEquipItem;
                _loc_3.sort(this.sortFun);
                _loc_4 = _loc_3.filter(this.filterFun);
            }
            else
            {
                _loc_4 = DefenseCopyShopConfig.instance.allScrollItem;
                _loc_4.sort(this.sortFun);
            }
            var _loc_5:Array = [];
            var _loc_6:* = _loc_4.length;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            while (_loc_8 < _loc_6)
            {
                
                if (_loc_4[_loc_8] && this.canShow(_loc_4[_loc_8]) == false)
                {
                }
                else
                {
                    _loc_9 = Math.floor(_loc_7 / 3);
                    if (_loc_5[_loc_9] == null)
                    {
                        _loc_5[_loc_9] = new Array();
                    }
                    _loc_5[_loc_9].push(_loc_4[_loc_8]);
                    _loc_7++;
                }
                _loc_8++;
            }
            if (_loc_5.length == 0)
            {
                this._hh = _loc_5.length * this._list.rowHeight;
                this._bg.height = 47;
            }
            else
            {
                _loc_10 = _loc_5.length > 3 ? (3) : (_loc_5.length);
                this._hh = _loc_10 * this._list.rowHeight + this._list.y - 47;
                this._bg.height = this._list.y + _loc_10 * this._list.rowHeight;
            }
            this._list.dataProvider = new DataProvider(_loc_5);
            this._list.drawNow();
            if (_loc_4.length > 0)
            {
                _loc_11 = _loc_4[0] as TDefenseCopyShopSell;
                Dispatcher.dispatchEvent(new DataEvent(EventName.DefenseCopyComposeUpdate, _loc_11.itemCode));
            }
            return;
        }// end function

        private function canShow(param1:TDefenseCopyShopSell) : Boolean
        {
            if (GameConst.GuideDefenseCopyCode == Cache.instance.copy.copyInfo.code)
            {
                return param1.copycode == GameConst.DefenseCopyCode;
            }
            return param1.copycode == Cache.instance.copy.copyInfo.code;
        }// end function

        override public function get height() : Number
        {
            return this._hh;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._list = UIFactory.tileList(-5, 53, 240, 340, this);
            this._list.setStyle("cellRenderer", DefenseCopyUnfoldCellRenderer);
            this._list.columnWidth = 228;
            this._list.rowHeight = 113;
            this._list.direction = GBoxDirection.VERTICAL;
            this._bg = UIFactory.bg(0, -2, 241, 110, this, ImagesConst.DefenseCopyUnfoldSelectBg);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._list.dispose(param1);
            this._bg.dispose(param1);
            return;
        }// end function

    }
}
